<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['id']){
	$_SESSION['hotelid']=$_RQ['id'];
}
$hotelid=$_SESSION['hotelid'];
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'hotelid'=>$hotelid);
	if(!empty($_RQ['nickname'])){
		$params['nickname']=trim($_RQ['nickname']);
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if(isset($_RQ['openid'])){
		$params['openid']=intval($_RQ['openid']);
		$return['params']['openid']=$_RQ['openid'];
	}
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_jd_member',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员管理'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'realname','title'=>'真实姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
		),
		'search'=>array(
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
		)),
	);
	$return['htmls']=$htmls;
	
	exi($return);
	}
	if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_jd_member',array('id'=>$id));
	}else{
		exi('请选择会员','error');
	}
    $return['item']=$item;
	$return['manage']=array('1'=>'是','0'=>'否');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'会员设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员管理'),
		),
		'edit'=>array(
			'0'=>array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			'1'=>array('name'=>'avatar','title'=>'头像','type'=>'image'),
			'4'=>array('name'=>'realname','title'=>'真实姓名','type'=>'string'),
			'5'=>array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			'6'=>array('name'=>'mobile','title'=>'电话','type'=>'string'),
			'7'=>array('name'=>'manage','title'=>'是否管理员','type'=>'radio','options'=>'manage'),
			)
			);
	$return['sex']=array('1'=>'男','2'=>'女');
	$return['htmls']=$htmls;
	exi($return);
	}
	if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('nickname','avatar','openid','sex','realname','mobile','manage'),$postdata);
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_jd_member',$data,array('id'=>$id));
				exi('设置成功！');
			}
			}
	if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_jd_member',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_jd_member',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>